package rpc

import (
	"context"
	"github.com/liserc/open-socket/protocol/message"
	"github.com/openimsdk/tools/discovery"
	"github.com/openimsdk/tools/system/program"
	"google.golang.org/grpc"
)

type MessageRpc struct {
	registry discovery.SvcDiscoveryRegistry
	conn     grpc.ClientConnInterface
	Client   message.MessageClient
}

func NewMessageRpcClient(registry discovery.SvcDiscoveryRegistry, rpcRegisterName string) *MessageRpc {
	conn, err := registry.GetConn(context.Background(), rpcRegisterName)
	if err != nil {
		program.ExitWithError(err)
	}
	client := message.NewMessageClient(conn)
	return &MessageRpc{registry: registry, conn: conn, Client: client}
}
